package nxu.it.controller;

import nxu.it.model.ApiResult;
import nxu.it.service.GreetingService;
import org.noear.solon.annotation.Controller;
import org.noear.solon.annotation.Get;
import org.noear.solon.annotation.Inject;
import org.noear.solon.annotation.Mapping;
import org.noear.solon.boot.web.MimeType;
import org.noear.solon.core.handle.ModelAndView;

@Controller
public class MainController {
    @Inject
    GreetingService greetingService;

    @Mapping(value = "/", produces = MimeType.TEXT_HTML_VALUE)
    @Get
    public String index() {
        return "<h1>Yes, it works!</h1>";
    }

    @Mapping(value = "/hello", produces = MimeType.TEXT_HTML_VALUE)
    @Get
    public String hello(String name) {
        return greetingService.sayHello(name);
    }

    @Mapping(value = "/json", produces = MimeType.APPLICATION_JSON_UTF8_VALUE)
    @Get
    public ApiResult json() {
        return ApiResult.ok("请求成功");
    }

    @Mapping(value = "/render", produces = MimeType.TEXT_HTML_VALUE)
    @Get
    public ModelAndView render() {
        ModelAndView mv = new ModelAndView("test.ftl");
        mv.put("name", "张三");
        return mv;
    }
}